#include <iostream>
#include <iomanip>
#include "equationsolver.h"
#include <limits>

const double pi = acos(-1);
const double eps = std::numeric_limits<double>::epsilon();

using namespace std;

//B题各函数
double func1(double x)
{
        return 1/x - tan(x);
}

double func2(double x)
{
        return 1/x - pow(2,x);
}

double func3(double x)
{
        return pow(2,-x) + exp(x) + 2*cos(x) -6 ;
}

double func4(double x)
{
        return (x*x*x + 4*x*x + 3*x + 5)/(2*x*x*x - 9*x*x + 18*x - 2);
}

int main()
{
    typedef double (*fp)(double);
    fp fpi[] = {func1, func2, func3, func4};
    myfunc f1(fpi[0]);
    myfunc f2(fpi[1]);
    myfunc f3(fpi[2]);
    myfunc f4(fpi[3]);

    double err = std::numeric_limits<double>::epsilon();
    bisection B1(0,pi/2,err,err,100,f1);
    bisection B2(0,pi/2,err,err,100,f2);
    bisection B3(0,pi/2,err,err,100,f3);
    bisection B4(0,pi/2,err,err,100,f4);

    cout << "Question B: " << endl;
    cout << "The bisection result of f1 is " << setiosflags(ios::fixed) << setprecision(2) << B1.solve() << endl;
    cout << "The bisection result of f2 is " << setiosflags(ios::fixed) << setprecision(2) << B2.solve() << endl;
    cout << "The bisection result of f3 is " << setiosflags(ios::fixed) << setprecision(2) << B3.solve() << endl;
    cout << "The bisection result of f4 is " << setiosflags(ios::fixed) << setprecision(2) << B4.solve() << endl;
    cout << endl;

    return 0;
}